package com.enjoyor.soa.traffic.server.efoms.dubbo.listener;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.enjoyor.soa.traffic.core.efoms.domain.DeviceDetailInfo;
import com.enjoyor.soa.traffic.core.efoms.domain.DeviceStatusInfo;
import com.enjoyor.soa.traffic.core.efoms.enums.EnumDicPublic;
import com.enjoyor.soa.traffic.core.efoms.service.IDevStatusInfoService;
import com.enjoyor.soa.traffic.core.efoms.service.IDeviceDetailInfoService;
import com.enjoyor.soa.traffic.server.efoms.common.Global;
import com.enjoyor.soa.traffic.server.efoms.helper.FTPAllFilesHelper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;

@Component
public class SynDeviceStatusListener implements CommandLineRunner {

    @Autowired
    private IDevStatusInfoService devStatusInfoService;
    @Autowired
    private IDeviceDetailInfoService deviceDetailInfoService;
    
    @Value("${ftp.upload.ip}")
    private String ftpIp;
	@Value("${ftp.upload.port}")
    private String ftpPort;
	@Value("${ftp.upload.user}")
    private String ftpUser;
	@Value("${ftp.upload.password}")
    private String ftpPassword;
    
    @Override
    public void run(String... args) throws Exception {
        // TODO Auto-generated method stub
        try {
            //获取所有的设备状态数据
        	List<DeviceStatusInfo> deviceStatusInfoList = devStatusInfoService.selectDeviceStatusList(null, 
        			null, null, null, null, null, null);
        	if(null != deviceStatusInfoList && deviceStatusInfoList.size() > 0 ) {
        		for(DeviceStatusInfo deviceStatusInfo : deviceStatusInfoList) {
        			String key = deviceStatusInfo.getDevTypeCode() + "-" + deviceStatusInfo.getDevId();
        			Global.DevStatusPool.put(key, deviceStatusInfo);
        		}
        	}
        	//获取所有的设备基础数据
        	List<DeviceDetailInfo> deviceDetailInfoList = deviceDetailInfoService.selectDeviceDetailInfoList(null, 
        			null, null, null, null, null, null);
        	if(null != deviceDetailInfoList && deviceDetailInfoList.size() > 0 ) {
        		for(DeviceDetailInfo deviceDetailInfo : deviceDetailInfoList) {
        			String key = deviceDetailInfo.getDevTypeCode() + "-" + deviceDetailInfo.getDevId();
        			Global.DeviceInfoPool.put(key, deviceDetailInfo);
        		}
        	}
        } catch (Exception e) {
            // throw e;
            return;
        }
    }
}
